package cn.broadsense.thrid.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.format.FastDateFormat;

import java.util.Date;
import java.util.TimeZone;

/**
 * utc 时间转换
 *
 * @author pengxin
 * @date 2022-10-20 15:40
 */
public class DateUTCUtils {

    /**
     * utc 时间
     */
    private static FastDateFormat YYYY_MM_DD_HH_MM_SS_FORMAT = FastDateFormat.getInstance("yyyyMMdd'T'HHmmss'Z'", TimeZone.getTimeZone("UTC"));

    /**
     * 转 utc  yyyyMMdd'T'HHmmss'Z'
     *
     * @param date
     * @return
     */
    public static String toUTCYYMM(Date date){
       return DateUtil.format(date, YYYY_MM_DD_HH_MM_SS_FORMAT);
    }

    /**
     * utc 转时间
     *
     * @param utcDate
     * @return
     */
    public static Date utcToDate(String utcDate){
       return DateUtil.parse(utcDate,YYYY_MM_DD_HH_MM_SS_FORMAT);
    }
}
